/**
 * Created by Administrator on 2017/11/18.
 */
var CONSTANTS_BUS = "汇总（业务）";
var CONSTANTS_LABEL_ACCOUNT = "汇总（账户）";
var CONSTANTS_ALL="ALL";
var CONSTANTS_SPLIT_="<br>";
var myTrello = {
    "totalLabelArray": [],
    "account_label_array": [],
    "bus_label_array": [],
    "typeList": ["ALL", CONSTANTS_LABEL_ACCOUNT, CONSTANTS_BUS]
};
myTrello.getBoard=function (boardId) {
    Trello.get("/boards/" + boardId, {
        cards: "open",
        lists: "open",
        checklists: "all",
        members: "all"
    }, function (board) {
        global.boards.push(board);
        global.boardIndex=global.boardIndex+1;
        if( global.boardIndex<global.boardList.length)
        {
            myTrello.getBoard(global.boardList[global.boardIndex]);
        }
        else
        {
            myTrello.getLabels(global.boardList[0]);
        }
    });


}
myTrello.getLabels = function (boardId) {
    Trello.get("/boards/" + boardId + "/labels", {label_fields: "all"}, function (labelArray) {
        labelArray.forEach(function (e) {
            myTrello.addLabel(e);

        });
        global.labelIndex=global.labelIndex+1;
        if(global.labelIndex<global.boardList.length)
        {
            myTrello.getLabels(global.boardList[global.labelIndex]);
        }
        else
        {
            myTrello.getDataFromBoard();
        }
    });

}
myTrello.getDataFromBoard = function () {
    console.log("global.checklists.size=" + global.checklists.length);
    global.boards.forEach(function (board) {
        global.cards = global.cards.concat(board.cards);
        global.lists = global.lists.concat(board.lists);
        global.checklists = global.checklists.concat(board.checklists);
        global.members = global.members.concat(board.members);
    });
    global.isfirst = false;
     myTrello.filterTopCard(CONSTANTS_ALL);
     myTrello.generateHtml(CONSTANTS_ALL);
}
myTrello.addLabel = function (label) {
    for (var i = 0; i < this.totalLabelArray.length; i++) {
        if (this.totalLabelArray[i] == label.id) {
            return;
        }
    }
    myTrello.totalLabelArray.push(label.id);
    if (label.name == CONSTANTS_BUS) {
        myTrello.bus_label_array.push(label.id);
    }
    else if (label.name == CONSTANTS_LABEL_ACCOUNT) {
        myTrello.account_label_array.push(label.id);
    }

}